home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
'92_HACK
/
IR_MAN_
/
ATOB.C
< prev
next >
Wrap
Text File
|
1992-06-07
|
2KB
|
114 lines
/* Analog to Binary converter routine.
By: Mike Neil 6/6/92
*/
#include "atob.h"
#ifdef IRDEBUG
#include "stdio.h"
#endif
#include "Movies.h"
long
AnalizeData(unsigned char *TheData, long dataSize) {
long ammount;
register long cnt;
register short delt;
register short state;
register short curChar;
short searchMode = 1;
short bitCnt;
long counter, duration;
char bits[20];
long outVal, lastVal;
long failSafeCnt;
state = 0;
bits[12] = 0;
bitCnt = 0;
outVal = 0;
failSafeCnt = 0;
lastVal = 0;
for (cnt = 0; cnt < dataSize-1; cnt++) {
curChar = TheData[cnt];
if ((curChar > 150) && (searchMode)) {
searchMode = 0;
#ifdef IRDEBUG
printf("osm!\n");
#endif
}
if (!searchMode) {
if (cnt % 500L == 1)
MoviesTask(nil, DoTheRightThing);
delt = (TheData[cnt+1] - TheData[cnt]);
if ((delt < 5) && (delt > -5)) {
failSafeCnt++;
if ((failSafeCnt > 200) && (state > 0)) {
state = 0;
bits[12] = 0;
bitCnt = 0;
outVal = 0;
failSafeCnt = 0;
}
}
else
failSafeCnt = 0;
if ((delt > 30) && (state == 0)) {
state = 1;
counter = 0;
}
if ((curChar > 170) && (state == 1)) {
counter++;
}
if ((delt < -30) && (state == 1) && (counter > 8)) {
state = 3;
counter = cnt;
}
if ((delt > 30) && (state == 3)) {
state = 4;
}
if ((delt < -30) && (state == 4)) {
duration = cnt - counter;
state = 3;
counter = cnt;
if (duration > 35) {
bits[bitCnt] = '1';
outVal = outVal | (1L << bitCnt);
} else
bits[bitCnt] = '0';
bitCnt++;
if (bitCnt > 11) {
state = 5;
#ifdef IRDEBUG
printf ("val : %ld\n", outVal); */
#endif
if ((outVal == lastVal) && (outVal))
return(outVal);
else {
lastVal = outVal;
}
}
}
if ((curChar > 80) && (state == 5)) {
state = 0;
bits[12] = 0;
bitCnt = 0;
outVal = 0;
failSafeCnt = 0;
}
}
}
return(0);
}